package ink.onei.production.service.impl;

import ink.onei.production.entity.AdminUser;
import ink.onei.production.exception.OperateException;
import ink.onei.production.mapper.ISystemMapper;
import ink.onei.production.service.ISystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: dang
 * @Description: TODO
 * @Date: 2023/12/26 20:57 星期二
 */
@Service
public class SystemServiceImpl implements ISystemService {

    @Autowired
    ISystemMapper systemMapper;

    // tempUser 查询账号是否在数据库中
    // adminUser 查询密码是否正确
    @Override
    public AdminUser login(AdminUser adminUser) {
        // @formatter:off
        AdminUser tempUser = new AdminUser();tempUser.setUsername(adminUser.getUsername());
        if (systemMapper.getAdminUserDynamic(tempUser) == null) throw new OperateException("账号不存在");
        else {
            AdminUser user = systemMapper.getAdminUserDynamic(adminUser);
            if (user == null) throw new OperateException("账号或密码错误");
            else
                return adminUser;
            // @formatter:on
        }
    }

    @Override
    public AdminUser getAdminUserDynamic(AdminUser adminUser) {
        return systemMapper.getAdminUserDynamic(adminUser);
    }
}
